<?php
session_start ();
include_once '../../Model/Room.php';
$room = new Room ();
?>
<div id="informx" style="width: 98.5%"></div>
<table class="ctable" id="tblPayBill" width="100%" height="100px">
<tr>
	<td align=right width="10%">月: </td>
	<td width="15%" >
	<select id="slMonth" style="width:60%;">
		<?php 
		for($i=1;$i<=12;$i++){
			if($i>=1 && $i<=9){
				echo '<option value=0'.$i.'>'.$i.' 月</option>';
			}else 
				echo '<option value='.$i.'>'.$i.' 月</option>';			
		}		
		?>
	</select>
	</td>
	<td align=right width="5%">年: </td>		
	<td width="15%">
		<input type="text" id="txtYear" name="txtYear" class="cinput" style="width: 70%;height: 21px;"/>
	</td>
	<td align=left width="55%">
		<input type="button" class="cbutton" name="btnCSV" id="btnCSV" value=" CSV ファイル "></input>
	</td>
</tr>
</table>
<input type="hidden" name="hidUser" id="hidUser" value=<?php echo $_SESSION['username'];?>></input>
<script type="text/javascript">
$(document).ready(function() {
	var now = new Date();	
	mm = now.getMonth();	
	dd = now.getDate();
	if(dd<=9 && dd>=1){
		dd = '0'+dd;	
	}
	$("#slMonth").attr("selectedIndex", mm);
	$("#txtYear").val(now.getFullYear());	
	//alert($('#hidUser').val());
	
	$("#btnCSV").click(function(){
		$("#informx").html('');
		if(isNaN($("#txtYear").val()) || $("#txtYear").val() < 0){
			_inform("informx", "Năm nhập không đúng!");
			return;
		}
		
		$date = dd+'/'+$("#slMonth").val()+'/'+$("#txtYear").val();
		var path='date='+$date+'&username='+$('#hidUser').val();
		
		$.ajax({
			type:"POST",
			url: "data/room/paybill/file_csv.php",
			data: path,
	        async: false,
			success: function(data) { 
				window.location.href = 'data/include/download.php?f=upload/csv/'+data; 
			}
		});

	});
});
</script>